package com.bigflexlib.utils
{
	public class Projection
	{
		
		
		public var arcs:Array = [];
		
		
		
		public function Projection( arcs:Array )
		{
			this.arcs = arcs;
		}

		public function get lastArc( ):Arc
		{
			return arcs[arcs.length-1] as Arc;
		}
		
		
		
		
		/**
		 * 
		 * 
		 * 
		 * @param fromVar
		 * @param toVar
		 * @param varNameFactory
		 *		a function like createVarName( str:String ):String
		 * @return 
		 * 
		 */		
		public function getBGPs( fromVar:String, toVar:String, varNameFactory:Function ):Array
		{
		
			var arr:Array = []
			
			var fromV:String = fromVar;
			var toV:String;
		
			for each ( var arc:Arc in arcs )
			{
			
				if ( arc == lastArc )
				{
					arr.push( arc.getBGP( fromV, toV ) );								
					break;
				}

				toV = "?" + varNameFactory( arr.join( " " ) );
				arr.push( arc.getBGP( fromV, toV ) );
				fromV = toV;
			}	
		
			return arr;
		}
		
		
		
		


		public static function fromString( str:String ):Projection
		{

			var arcs:Array = str.split(" ");
			
			for ( var i:int=0; i<arcs.length; i++ )
			{
				arcs[i] = Arc.fromString( arcs[i] );
			}		
		
			return new Projection( arcs );
		}

	}
}